]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
MessageTray: don't list the sources all the time
authorGiovanni Campagna <gcampagna@src.gnome.org>
Sun, 12 May 2013 18:13:43 +0000 (20:13 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Sun, 12 May 2013 19:06:34 +0000 (21:06 +0200)
The point of a hash table is that you don't need to list all the
elements. To avoid that, keep a "clearableCount" in MessageTray,
which can be used by the message tray menu to show and hide the
clear item, and that is updated in constant time when sources
are added or removed.

https://bugzilla.gnome.org/show_bug.cgi?id=700194

js/ui/messageTray.js

index 5cdaf2dc4f123332e9549602efa8dbf08c7ac708..8c24812d1a385705431daff36b959aa291dcfd56 100644 (file)
@@ -1530,11 +1530,7 @@ const MessageTrayContextMenu = new Lang.Class({
     },
 
     _updateClearSensitivity: function() {
-        let sources = this._tray.getSources();
-        sources = sources.filter(function(source) {
-            return !source.trayIcon && !source.isChat && !source.resident;
-        });
-        this._clearItem.setSensitive(sources.length > 0);
+        this._clearItem.setSensitive(this._tray.clearableCount > 0);
     },
 
     setPosition: function(x, y) {
@@ -1660,6 +1656,8 @@ const MessageTray = new Lang.Class({
         this._desktopClone = null;
         this._inCtrlAltTab = false;
 
+        this.clearableCount = 0;
+
         this._lightbox = new Lightbox.Lightbox(global.overlay_group,
                                                { inhibitEvents: true,
                                                  fadeInTime: ANIMATION_TIME,
@@ -1896,6 +1894,9 @@ const MessageTray = new Lang.Class({
             this._summary.insert_child_at_index(summaryItem.actor, this._chatSummaryItemsCount);
         }
 
+        if (!source.trayIcon && !source.isChat && !source.resident)
+            this.clearableCount++;
+
         this._sources.set(source, obj);
 
         obj.notifyId = source.connect('notify', Lang.bind(this, this._onNotify));
@@ -1937,6 +1938,9 @@ const MessageTray = new Lang.Class({
         if (source.isChat)
             this._chatSummaryItemsCount--;
 
+        if (!source.trayIcon && !source.isChat && !source.resident)
+            this.clearableCount--;
+
         source.disconnect(obj.notifyId);
         source.disconnect(obj.destroyId);
         source.disconnect(obj.mutedChangedId);